<extend name="Index/index" />
<block name="center">
<div class="panel panel-blue">
    <div class="panel-heading">添加管理员</div>
	    <div class="panel-body pan">
	        	<form action="{:U('Admin/Uadmin/insert')}" class="form-horizontal" method="post">
	            	<div class="form-actions top">
	                	
	            	</div>
	            	<div class="form-body pal">
		                <div class="form-group">
		                    <label for="inputAddress" class="col-md-3 control-label">用户名称 <span class="require">*</span>
		                    </label>
		                    <div class="col-md-9">
		                        <div class="input-icon right" ><i class="fa fa-location-arrow"></i>
		                            <div style="float:left"><input type="text" placeholder="请输入6~18位字母数字下划线" class="form-control" name="ausername" id="Uadmin" style="width:300px"></div><div style="float:left"><span id="con" error="输入的用户名已存在" success="√" kong="用户名格式错误" style="font-size:20px"></span></div>
		                        </div>
		                    </div>
	                	</div>
	                	 <div class="form-group">
		                   	<label for="inputAddress" class="col-md-3 control-label">用户密码 <span class="require">*</span>
		                    </label>
		                    <div class="col-md-9">
		                        <div class="input-icon right" ><i class="fa fa-location-arrow"></i>
		                            <div style="float:left"><input type="password" placeholder="请输入6~18位的非空字符" class="form-control" name="apassword" id="Upass" style="width:300px"></div><div style="float:left"><span id="pcon" error="输入的密码格式错误" success="√" kong="密码不能为空" style="font-size:20px"></span></div>
		                        </div>
		                    </div>
	                	</div>
                         <div class="form-group">
                            <label for="inputAddress" class="col-md-3 control-label">管理权限<span class="require">*</span>
                            </label>
                            <div class="col-md-9">
                                <div class="input-icon right" ><i class="fa fa-location-arrow"></i>
                                    <div style="float:left"><select class="form-control" name="group_id" style="width:300px">
                                    	<foreach name="ginfo" item="vo" > 
                                        <option value="{$vo['id']}">{$vo['title']}</option>
                                        </foreach>
                                    </select></div><div style="float:left"></div>
                                </div>
                            </div>
	            	</div>
	            	<div class="form-actions">
	                	<div class="col-md-offset-3 col-md-9">
                            <!-- <input type="hidden" name="id" value="{$info['0']['id']}"> -->
		                    <button type="submit" class="btn btn-primary">添加</button>&nbsp;
		                    <button type="reset" class="btn btn-green">重置</button>
	                	</div>
	            	</div>
	        	</form>
	   	 	</div>
		</div>
			<script type="text/javascript" src="__PUBLIC__/js/jquery-1.8.3.min.js"></script>
		<script type="text/javascript">
		$(function(){
			var ustatu = false;
			var pstatu = false;
			//判断用户名
			$('#Uadmin').blur(function(){
				//匹配正则
				var reg = /^\w{6,18}$/;//6~18位

				var uadmin = $(this).val();
				var res =  reg.test(uadmin);
				// alert(res);
				if(res == ''){
					// alert(2);
					// alert(1);
						var re = $('#con').attr('kong');
						// console.log(re);
						$('#con').html(re).css('color','red');
						ustatu = false;
						// die();
				}else{
						// alert(res);
						// $.post('{:U("Admin/Uadmin/ajax")}',{'res':uadmin},function(data){
						// 	// alert(data);
						// 	if(data == 1){
						// 		// alert(1);
						// 		var re = $('#con').attr('success');
						// 		// console.log(re);
						// 		$('#con').html(re).css('color','blue');
						// 		ustatu = true;
						// 	}else{
						// 		// alert(0);
						// 		var re = $('#con').attr('error');
						// 		$('#con').html(re).css('color','red');
						// 		ustatu = false;
						// 		// console.log(re);
						// 	}
						// });

						$.ajax({
							url:'{:U("Admin/Uadmin/ajax")}',
							data:{'res':uadmin},
							type:'POST',
							success: function(data){
								if(data == 1){
									// alert(1);
									var re = $('#con').attr('success');
									// console.log(re);
									$('#con').html(re).css('color','blue');
									ustatu = true;
								}else{
									// alert(0);
									var re = $('#con').attr('error');
									$('#con').html(re).css('color','red');
									ustatu = false;
									// console.log(re);
								}
							},
							async: false//是否异步  x.open('GET','1.php', true);
						});
					}

				// var statu = false;
				$('#Upass').blur(function(){
					//匹配正则
					var reg = /^\S{6,18}$/;
					var Upass = $(this).val();
					var res =  reg.test(Upass);
					// alert(res);
					if(res == ''){
						// alert(2);
						// alert(1);
							var re = $('#pcon').attr('error');
							// console.log(re);
							$('#pcon').html(re).css('color','red');
							pstatu = false;
							// die();	
						}else{
							// alert(0);
							var re = $('#pcon').attr('success');
								// console.log(re);
								$('#pcon').html(re).css('color','blue');
								// statu = true;
							pstatu = true;
							// console.log(re);
						}
					})
				
			})
			$('.form-horizontal').submit(function(){
				$('#Uadmin').trigger('blur');
				$('#Upass').trigger('blur');
				if(ustatu && pstatu){ 
					return true;
				}else{
					return false;
				}
			})
		})
		</script>

</block>